package com.learing.handler.pipeline;

import com.learing.message.MessageRequestPacket;
import com.learing.message.MessageResponsePacket;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.SimpleChannelInboundHandler;

import java.util.Date;

public class MessageResponseHandler extends SimpleChannelInboundHandler<MessageResponsePacket> {
    @Override
    protected void channelRead0(ChannelHandlerContext ctx, MessageResponsePacket messageResponsePacket) {
        ctx.channel().writeAndFlush(receiveMessage(messageResponsePacket));
    }

    private MessageResponsePacket receiveMessage(MessageResponsePacket messageResponsePacket) {
        System.out.println(new Date() + ": 收到服务端的消息: " + messageResponsePacket.getMessage());
        return messageResponsePacket;
    }
}